package com.tz.farmer.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.smartPark.msframe.result.ResultEx;
import com.tz.farmer.enums.ErrorCodeEnum;
import com.tz.farmer.model.BusinessInfo;
import com.tz.farmer.service.WebFarmerDataService;
import com.tz.farmer.so.*;
import com.tz.farmer.util.HttpUtils;
import com.tz.farmer.util.ResultExM;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 营养推荐
 */
@Api(tags = "台农、渔 ")
@Slf4j
@RestController
@RequestMapping("/nongyu")
public class WebFarmerDataController {

    Logger logger = LoggerFactory.getLogger(WebFarmerDataController.class);

    @Autowired
    RestTemplate restTemplate;

    @Resource
    WebFarmerDataService webFarmerDataService;

    @Resource
    JdbcTemplate jdbcTemplate;

    /**
     * 根据企业名称查询旗下的统一社会代码及其数据
     *
     * @param name
     * @return
     */
    @GetMapping("/namelist")
    @ApiOperation("查询名称列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "", dataType = "string", defaultValue = "", required = true)
    })
    public ResultEx getNameByConditions(String name) {

        String url = "http://61.175.223.173:34080/data?name={1}";
        ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class, name);
        String body = responseEntity.getBody();
        if (body != null) {
            JSONObject data = (JSONObject) JSON.parse(body);
            return ResultExM.builder().makeResult(ErrorCodeEnum.ERR_COMMON_SUCCEED, data);
        }
        return ResultExM.builder().makeFailedResult();
    }

    /**
     * 根据企业名称查询旗下的统一社会代码及其数据
     *
     * @param name
     * @return
     */
    @GetMapping("/nameone")
    @ApiOperation("查询信息列表根据具体名称")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "", dataType = "string", defaultValue = "", required = true)
    })
    public ResultEx getNutritionListByConditions(String name) {

        String url = "http://61.175.223.173:34080/word?name={1}";
        ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class, name);
        String body = responseEntity.getBody();
        if (body != null) {
            JSONObject data = (JSONObject) JSON.parse(body);
            return ResultExM.builder().makeResult(ErrorCodeEnum.ERR_COMMON_SUCCEED, data);
        }
        return ResultExM.builder().makeFailedResult();
    }

    /**
     * 区县列表
     *
     * @param
     * @return
     */
    @GetMapping("/addr")
    @ApiOperation("区县列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "", value = "", dataType = "", defaultValue = "", required = false)
    })
    public ResultEx getaddr() {
        List list = new ArrayList();
        list.add("椒江区");
        list.add("黄岩区");
        list.add("路桥区");
        list.add("玉环市");
        list.add("三门县");
        list.add("天台县");
        list.add("仙居县");
        list.add("温岭市");
        list.add("临海市");
        return ResultExM.builder().makeResult(ErrorCodeEnum.ERR_COMMON_SUCCEED, list);
    }


    /**
     * 船舶基础信息
     *
     * @param
     * @return
     */
    @GetMapping("/boat")
    @ApiOperation("船舶基础信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "country", value = "区", dataType = "string", defaultValue = "", required = false),
            @ApiImplicitParam(name = "keyword", value = "船ID，船集港，船名", dataType = "string", defaultValue = "", required = false),
            @ApiImplicitParam(name = "people", value = "船舶所有人", dataType = "string", defaultValue = "", required = false),
            @ApiImplicitParam(name = "phone", value = "电话", dataType = "string", defaultValue = "", required = false),
            @ApiImplicitParam(name = "currentPage", value = "当前页", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", defaultValue = "", required = true)
    })
    public ResultEx getBoatListByConditions(String country, String keyword, String people, String phone, String currentPage, String pageSize) {
        int curPage = Integer.parseInt(currentPage);
        int size = Integer.parseInt(pageSize);
        int n = (curPage-1)*size;
        String sql1 ="select count(0) from BIZ_1000_MOBILE_TZ where 1=1";
        int total = jdbcTemplate.queryForObject(sql1,Integer.class);
        logger.info("查询总数sql：：："+sql1);
        logger.info("查询总数：：："+total);
        String sql = "SELECT BIZ_1000_MOBILE_TZ.MOBILE_ID,\n" +
                "    BIZ_1000_MOBILE_TZ.FI_FISHERHOMELAND,\n" +
                "    BIZ_1000_MOBILE_TZ.MOBILENAME,\n" +
                "    BIZ_1000_MOBILE_TZ.FI_FISHERSTUFF,\n" +
                "    BIZ_1000_MOBILE_TZ.FI_FISHERTYPE,\n" +
                "    BIZ_1000_MOBILE_TZ.CITY,\n" +
                "    BIZ_1000_MOBILE_TZ.COUNTRY,\n" +
                "    BIZ_1000_MOBILE_TZ.TOWN,\n" +
                "    BIZ_1000_MOBILE_TZ.VILLAGE,\n" +
                "    BIZ_1000_MOBILE_TZ.FI_TASKTYPE,\n" +
                "    BIZ_1000_MOBILE_TZ.FI_TASKTRAIT,\n" +
                "    BIZ_1000_MOBILE_TZ.MMSI,\n" +
                "    BIZ_1000_MOBILE_TZ.FI_TOTALLENGTH,\n" +
                "    BIZ_1000_MOBILE_TZ.FI_FISHERLENGTH,\n" +
                "    BIZ_1000_MOBILE_TZ.FI_FISHERWIDTH,\n" +
                "    BIZ_1000_MOBILE_TZ.FI_FISHERDEPTH,\n" +
                "    BIZ_1000_MOBILE_TZ.FI_TOTALTON,\n" +
                "    BIZ_1000_MOBILE_TZ.FI_MINETON,\n" +
                "    BIZ_1000_MOBILE_TZ.FI_MAINPOWER,\n" +
                "    BIZ_1000_MOBILE_TZ.FI_RADIO,\n" +
                "    BIZ_1000_MOBILE_TZ.FI_AIRDOOR,\n" +
                "    BIZ_1000_MOBILE_TZ.FI_OWNERNAME,\n" +
                "    BIZ_1000_MOBILE_TZ.FI_OWNERPHONE,\n" +
                "    BIZ_1000_MOBILE_TZ.FI_OWNERMOBILE,\n" +
                "    BIZ_1000_MOBILE_TZ.FI_TESTNUM,\n" +
                "    BIZ_1000_MOBILE_TZ.SATELLITE_PHONE,\n" +
                "    BIZ_1000_MOBILE_TZ.TERMINAL_ID,\n" +
                "    BIZ_1000_MOBILE_TZ.TERMINAL_TYPE,\n" +
                "    BIZ_1000_MOBILE_TZ.TERMINAL_CODE \n" +
                "    FROM BIZ_1000_MOBILE_TZ where 1=1  limit "+n+","+size;
        logger.info("查询sql为：：：：：："+sql);
        List<Map<String , Object>> list1 = jdbcTemplate.queryForList(sql);
        Map<String , Object> map = new HashMap<>();
        map.put("total",total);
        map.put("data",list1);
        return ResultExM.builder().makeResult(ErrorCodeEnum.ERR_COMMON_SUCCEED, map);

    }


    /**
     * 渔获物溯源信息
     *
     * @param
     * @return
     */
    @GetMapping("/thing")
    @ApiOperation("渔获物溯源信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "string", defaultValue = "", required = false),
            @ApiImplicitParam(name = "endTime", value = "结束时间", dataType = "string", defaultValue = "", required = false),
            @ApiImplicitParam(name = "traded", value = "被交易方", dataType = "string", defaultValue = "", required = false),
            @ApiImplicitParam(name = "yType", value = "渔获种类", dataType = "string", defaultValue = "", required = false),
            @ApiImplicitParam(name = "currentPage", value = "当前页", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", defaultValue = "", required = true)
    })
    public ResultEx getThingConditions(String startTime, String endTime, String traded, String yType, String currentPage, String pageSize) {

        int curPage = Integer.parseInt(currentPage);
        int size = Integer.parseInt(pageSize);
        int n = (curPage-1)*size;

        String  sql1 = "SELECT count(0) FROM BIZ_1000_YHWSY  where 1=1 ";
        int total = jdbcTemplate.queryForObject(sql1,Integer.class);
        logger.info("查询条数：：：：：："+total);


        String sql = "   SELECT  b.ID,    b.LRMC,\n" +
                "    b.DFMC,\n" +
                "    b.ZYLX,\n" +
                "    b.YHZL,\n" +
                "    b.ZYYQ,\n" +
                "    b.YHSL,\n" +
                "    b.GGDW,\n" +
                "    b.YHGG,\n" +
                "    b.JYLX,\n" +
                "    b.XM,\n" +
                "    b.SYLX,\n" +
                "    b.SAGK,\n" +
                "    b.YHMDD,\n" +
                "    b.MDDMC\n" +
                "    FROM BIZ_1000_YHWSY b  where 1=1  limit "+n+","+size;
        logger.info("查询sql为：：：：：："+sql);
        List<Map<String , Object>> list = jdbcTemplate.queryForList(sql);
        Map<String , Object> map = new HashMap<>();
        map.put("total",total);
        map.put("data",list);
        return ResultExM.builder().makeResult(ErrorCodeEnum.ERR_COMMON_SUCCEED, map);


    }



    //////////////////////////主体///////////////////////////

    /**
     * 添加查询列表
     *
     * @param so
     * @return
     */
    @PostMapping("/addLead")
    @ApiOperation("添加主体信息 农 渔 统一接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "businessName", value = "主题名称", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "uniscId", value = "信用代码", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "businessPersonName", value = "联系人", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "phone", value = "联系电话", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "zipCode", value = "邮编", dataType = "int", defaultValue = "", required = false),
            @ApiImplicitParam(name = "businessAddress", value = "地址", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "scale", value = "规模", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "leadingProduct", value = "主导产品", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "city", value = "区县", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "property", value = "属性 331001 渔,331002 农", dataType = "string", defaultValue = "", required = true)
    })
    public ResultEx saveSubjectInformation(@RequestBody BusinessInfoSo so) throws Exception {
        ResultEx resultEx = webFarmerDataService.addBusinessInfo(so);
        if (resultEx.getRetCode() == 200) {
            BusinessInfo data = (BusinessInfo) resultEx.getData();
            logger.info("添加主题信息返回"+data.toString());
            BusinessController businessController = new BusinessController();
            String result=businessController.addZhuCe(data.getUniscId(), data.getProperty(), data.getPhone());
            logger.info("主体企业注册返回结果========================================="+result);
        }
        return resultEx;
    }

    /**
     * 修改主体信息
     *
     * @param so
     * @return
     */
    @PostMapping("/updateLead")
    @ApiOperation("修改主体信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "自增id", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "businessName", value = "主题名称", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "uniscId", value = "信用代码", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "businessPersonName", value = "联系人", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "phone", value = "联系电话", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "zipCode", value = "邮编", dataType = "int", defaultValue = "", required = false),
            @ApiImplicitParam(name = "businessAddress", value = "地址", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "scale", value = "规模", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "city", value = "主导产品", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "leadingProduct", value = "主导产品", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "isDelete", value = "软删除", dataType = "int", defaultValue = "", required = true)
    })
    public ResultEx updateSubjectInformation(@RequestBody BusinessInfoSo so) {
        return webFarmerDataService.updateBusinessInfo(so);
    }


    /**
     * 删除认证信息
     *
     * @param so
     * @return
     */
    @GetMapping("/deleteCertification")
    @ApiOperation("删除认证信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主题信息id", dataType = "int", defaultValue = "", required = true)
    })
    public ResultEx deleteAuthenticationInformation(EmptySo so) {
        return webFarmerDataService.deleteAuthenticationInfo(so);
    }

    /**
     * 修改产品认证信息
     *
     * @param so
     * @return
     */
    @PostMapping("/editCertification")
    @ApiOperation("修改认证信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "主键id", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "leadId", value = "主题信息id", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "authType", value = "认证类别", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "number", value = "编号证书", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "productName", value = "产品名称", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "yield", value = "批准产量", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "termTime", value = "有效期", dataType = "string", defaultValue = "", required = true)
    })
    public ResultEx updateAuthenticationInformation(@RequestBody AuthenticationInfoSo so) {
        return webFarmerDataService.updateAuthenticationInfo(so);
    }

    /**
     * 认证列表
     */
    @GetMapping("/list")
    @ApiOperation("根据主体ID查询认证信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "leadId", value = "", dataType = "int", defaultValue = "", required = false),
            @ApiImplicitParam(name = "currentPage", value = "当前页", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", defaultValue = "", required = true)
    })
    public ResultEx getAuthenticationInformation(AuthenticationInfoSo so) {
        return webFarmerDataService.getAuthenticationInfoByLeadId(so);
    }


    /**
     * 源头主题企业信息查询
     *
     * @param so
     * @return
     */
    @GetMapping("/getList")
    @ApiOperation("源头主题企业信息查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", value = "", dataType = "string", defaultValue = "", required = false),
            @ApiImplicitParam(name = "endTime", value = "", dataType = "string", defaultValue = "", required = false),
            @ApiImplicitParam(name = "keyword", value = "主题名称，信用代码", dataType = "string", defaultValue = "", required = false),
            @ApiImplicitParam(name = "nameorphone", value = "联系人，电话", dataType = "string", defaultValue = "", required = false),
            @ApiImplicitParam(name = "businessAddress", value = "地址", dataType = "string", defaultValue = "", required = false),
            @ApiImplicitParam(name = "property", value = "属性 331001 渔,331002 农", dataType = "string", defaultValue = "", required = false),
            @ApiImplicitParam(name = "currentPage", value = "当前页", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", defaultValue = "", required = true),
    })
    public ResultEx getBusinessInfoList(BusinessInfoSo so,@Param("request") HttpServletRequest request) {
        String userAccount = request.getHeader("userAccount");
        logger.info("用户账号为：：：：" + userAccount);
        return webFarmerDataService.getBusinessInfoList(so,userAccount);
    }

    /**
     * 添加产品认证信息
     *
     * @param so
     * @return
     */
    @PostMapping("/addCertification")
    @ApiOperation("批量添加产品认证信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "leadId", value = "主题信息id", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "authType", value = "认证类别", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "number", value = "编号证书", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "productName", value = "产品名称", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "yield", value = "批准产量", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "termTime", value = "有效期", dataType = "string", defaultValue = "", required = true)
    })
    public ResultEx saveAuthenticationInformation(@RequestBody EmptySo so) {
        return webFarmerDataService.addAuthenticationInfo(so);
    }


    ////////////////////////监测信息//////////////////////////////


    /**
     * 检测信息列表
     *
     * @param so
     * @return
     */
    @GetMapping("/detection")
    @ApiOperation("检测信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pInfoId", value = "", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "currentPage", value = "当前页", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", defaultValue = "", required = true)
    })
    public ResultEx getDetectionInfoList(DetectionInfoSo so) {
        return webFarmerDataService.getDetectionInfoList(so);
    }


    /**
     * 删除检测信息
     *
     * @param so
     * @return
     */
    @GetMapping("/deleteDetection")
    @ApiOperation("删除检测信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "int", defaultValue = "", required = true)
    })
    public ResultEx deleteDetectionInfo(DetectionInfoSo so) {
        return webFarmerDataService.deleteDetectionInfo(so);
    }

    /**
     * 单查检测信息
     *
     * @param so
     * @return
     */
    @GetMapping("/getOne")
    @ApiOperation("单查检测信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "int", defaultValue = "", required = true)
    })
    public ResultEx getOneDetectionInfo(DetectionInfoSo so) {
        return webFarmerDataService.getOneDetectionInfo(so);
    }

    /**
     * 修改检测信息
     *
     * @param so
     * @return
     */
    @PostMapping("/updateDetection")
    @ApiOperation("修改检测信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "url", value = "", dataType = "int", defaultValue = "", required = true)
    })
    public ResultEx updateDetectionInfo(@RequestBody DetectionInfoSo so) {
        return webFarmerDataService.updateDetectionInfo(so);
    }


    ///////////////////////////种植操作////////////////////////////////////

    /**
     * 种植信息列表
     *
     * @param so
     * @return
     */
    @GetMapping("/operate")
    @ApiOperation("种植信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pInfoId", value = "", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "currentPage", value = "当前页", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", defaultValue = "", required = true)
    })
    public ResultEx getOperateInfoList(OperateInfoSo so) {
        return webFarmerDataService.getOperateInfoList(so);
    }


    /**
     * 删除种植信息
     *
     * @param so
     * @return
     */
    @GetMapping("/deleteOperate")
    @ApiOperation("删除种植信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "int", defaultValue = "", required = true)
    })
    public ResultEx deleteOperateInfo(OperateInfoSo so) {
        return webFarmerDataService.deleteOperateInfo(so);
    }

    /**
     * 单查种植信息
     *
     * @param so
     * @return
     */
    @GetMapping("/getOneOperate")
    @ApiOperation("单查种植信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "int", defaultValue = "", required = true)
    })
    public ResultEx getOneOperateInfo(OperateInfoSo so) {
        return webFarmerDataService.getOneOperateInfo(so);
    }

    /**
     * 修改种植信息
     *
     * @param so
     * @return
     */
    @PostMapping("/updateOperate")
    @ApiOperation("修改种植信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "oType", value = "操作类型", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "pName", value = "产品名称", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "address", value = "生产地块", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "inThing", value = "投入品", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "people", value = "责任人", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "oTime", value = "操作时间", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "pInfoId", value = "产品信息id", dataType = "string", defaultValue = "", required = true)
    })
    public ResultEx updateOperateInfo(@RequestBody OperateInfoSo so) {
        return webFarmerDataService.updateOperateInfo(so);
    }


    ////////////////////////////交易信息///////////////////////////////////////////

    /**
     * 交易信息列表
     *
     * @param so
     * @return
     */
    @GetMapping("/trade")
    @ApiOperation("交易信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pInfoId", value = "", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "currentPage", value = "当前页", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", defaultValue = "", required = true)
    })
    public ResultEx getTradeInfoList(TradeInfoSo so) {
        return webFarmerDataService.getTradeInfoList(so);
    }


    /**
     * 删除交易信息
     *
     * @param so
     * @return
     */
    @GetMapping("/deleteTrade")
    @ApiOperation("删除交易信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "int", defaultValue = "", required = true)
    })
    public ResultEx deleteTradeInfo(TradeInfoSo so) {
        return webFarmerDataService.deleteTradeInfo(so);
    }

    /**
     * 单查交易信息
     *
     * @param so
     * @return
     */
    @GetMapping("/getOneTrade")
    @ApiOperation("单查交易信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "int", defaultValue = "", required = true)
    })
    public ResultEx getOneTradeInfo(TradeInfoSo so) {
        return webFarmerDataService.getOneTradeInfo(so);
    }

    /**
     * 修改交易信息
     *
     * @param so
     * @return
     */
    @PostMapping("/updateTrade")
    @ApiOperation("修改交易信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "url", value = "", dataType = "int", defaultValue = "", required = true)
    })
    public ResultEx updateTradeInfo(@RequestBody TradeInfoSo so) {
        return webFarmerDataService.updateTradeInfo(so);
    }


    ///////////////////////产品//////////////////////////////


    /**
     * 修改产品信息
     *
     * @param so
     * @return
     */
    @PostMapping("/updateProduct")
    @ApiOperation(" 修改产品信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "自增id", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "pName", value = "产品名称", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "weight", value = "重量", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "pickTime", value = "采摘时间", dataType = "int", defaultValue = "", required = true)
    })
    public ResultEx updateProductInfo(@RequestBody ProductInfoSo so) {
        return webFarmerDataService.updateProductInfo(so);
    }

    /**
     * 删除产品信息
     *
     * @param so
     * @return
     */
    @GetMapping("/deleteProduct")
    @ApiOperation("删除产品信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "自增id", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "leadId", value = "产品id", dataType = "int", defaultValue = "", required = true)
    })
    public ResultEx deleteProductInfo(ProductInfoSo so) {
        return webFarmerDataService.deleteProductInfo(so);
    }

    /**
     * 单插产品信息
     *
     * @param so
     * @return
     */
    @GetMapping("/getOneProduct")
    @ApiOperation("单查产品信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "自增id", dataType = "int", defaultValue = "", required = true)
    })
    public ResultEx getOneProductInfo(ProductInfoSo so) {
        return webFarmerDataService.getOneProductInfo(so);
    }


    /**
     * 产品信息列表
     *
     * @param so
     * @return
     */
    @GetMapping("/getListProduct")
    @ApiOperation("产品信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "产品id", dataType = "int", defaultValue = "", required = false),
            @ApiImplicitParam(name = "businessName", value = "主体信息", dataType = "string", defaultValue = "", required = false),
            @ApiImplicitParam(name = "pName", value = "产品名称", dataType = "string", defaultValue = "", required = false),
            @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "String", defaultValue = "", required = false),
            @ApiImplicitParam(name = "endTime", value = "结束时间", dataType = "String", defaultValue = "", required = false),
            @ApiImplicitParam(name = "currentPage", value = "当前页", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", defaultValue = "", required = true)
    })
    public ResultEx getProductInfoList(ProductInfoSo so,@Param("request") HttpServletRequest request) {
        String userAccount = request.getHeader("userAccount");
        logger.info("用户账号为：：：：" + userAccount);
        return webFarmerDataService.getProductInfoList(so,userAccount);
    }


    /**
     * 根据主体ID查询产品信息列表
     */
    @GetMapping("/productByleadId")
    @ApiOperation("根据主体ID查询产品信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "leadId", value = "", dataType = "int", defaultValue = "", required = false),
            @ApiImplicitParam(name = "currentPage", value = "当前页", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", defaultValue = "", required = true)
    })
    public ResultEx getProductInformation(ProductInfoSo so) {
        return webFarmerDataService.getProductInformation(so);
    }


    ///////////////////////////////////////


    /**
     * 添加产品、种植、交易、检测信息
     *
     * @param so
     * @return
     */
    @PostMapping("/addProduct")
    @ApiOperation("添加产品、种植、交易、检测信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pName", value = "产品名称", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "weight", value = "重量", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "pickTime", value = "采摘时间", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "oType", value = "操作类型", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "pName", value = "产品名称", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "address", value = "生产地块", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "inThing", value = "投入品", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "people", value = "责任人", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "oTime", value = "操作时间", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "pInfoId", value = "产品信息id", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "pInfoId", value = "产品id", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "tradeName", value = "客户名称", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "code", value = "统一信用代码", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "tradeTime", value = "交易时间", dataType = "date", defaultValue = "", required = true),
            @ApiImplicitParam(name = "tradeNum", value = "交易数量", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "pInfoId", value = "产品id", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "url", value = "图片得oss地址", dataType = "string", defaultValue = "", required = true),
            @ApiImplicitParam(name = "listTrade", value = "存放交易信息得list", dataType = "list", defaultValue = "", required = true),
            @ApiImplicitParam(name = "listOperate", value = "存放种植信息得list", dataType = "list", defaultValue = "", required = true),
            @ApiImplicitParam(name = "detection", value = "存放检测信息得对象", dataType = "object", defaultValue = "", required = true)
    })
    public ResultEx addProductInfo(@RequestBody ProductInfoSo so, @Param("request") HttpServletRequest request) {
        String userAccount = request.getHeader("userAccount");
        logger.info("用户账号为：：：：" + userAccount);
        so.setUserAccount(userAccount);
        return webFarmerDataService.addProductInfo(so);
    }



    /**
     * 添加检测信息
     *
     * @param so
     * @return
     */
    @PostMapping("/addDetection")
    @ApiOperation("添加检测信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pInfoId", value = "产品id", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "url", value = "图片得oss地址", dataType = "string", defaultValue = "", required = true)
    })
    public ResultEx addDetection(@RequestBody DetectionInfoSo so) throws Exception {
        return webFarmerDataService.addDetection(so);
    }

    /**
     * 添加交易
     *
     * @param so
     * @return
     */
    @PostMapping("/addTrade")
    @ApiOperation("添加交易信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pInfoId", value = "产品id", dataType = "int", defaultValue = "", required = true),
            @ApiImplicitParam(name = "list", value = "图片得oss地址", dataType = "string", defaultValue = "", required = true)
    })
    public ResultEx addTrade(@RequestBody TradeSo so) throws Exception {
        return webFarmerDataService.addTrade(so);
    }

    /**
     * 添加种植
     *
     * @param so
     * @return
     */
        @PostMapping("/addOperate")
        @ApiOperation("添加种植信息")
        @ApiImplicitParams({
                @ApiImplicitParam(name = "pInfoId", value = "产品id", dataType = "int", defaultValue = "", required = true),
                @ApiImplicitParam(name = "list", value = "", dataType = "string", defaultValue = "", required = true)
        })
        public ResultEx addOperate(@RequestBody OperateSo so) throws Exception {
            return webFarmerDataService.addOperate(so);
        }
    /**
     * 手动注册主体
     *
     * @param
     * @return
     */
        @PostMapping("/zc")
        @ApiOperation("手动注册主体")
        public void zc()  throws Exception{
            BusinessController businessController = new BusinessController();
            String result=businessController.addZhuCe("91331002350204273P", "331002", "13957685636");
            logger.info(result);
        }

}
